package com.situ.hr4.w.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.hr4.pojo.EngageInterview;
import com.situ.hr4.pojo.EngageResume;
import com.situ.hr4.w.service.JLGLservice;
import com.situ.hr4.w.service.MSGLservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.beans.PropertyEditor;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

//面试管理
@Controller
public class MSGLcontroller {
    //时间类型转换器
    @InitBinder  //
    public void dateconvert(WebDataBinder bind){
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        PropertyEditor n=new CustomDateEditor(format, true);
        bind.registerCustomEditor(Date.class, n);
    }


    @Autowired
    MSGLservice msgl;

    @Autowired
    JLGLservice jlgl;


    //面试结果登记
    @RequestMapping("a6")
    public String a6(Map map,
                     @RequestParam(defaultValue = "1",required = false) Integer startPage,
                     @RequestParam(defaultValue = "3",required = false) Integer PageSize){

        PageHelper.startPage(startPage, PageSize ); //使用分页插件
        //查询所有复核通过的
        List<Map> list=msgl.jlqc();
       // System.out.println(list.size());
        PageInfo pageInfo=new PageInfo(list, 3);
        map.put("pageInfo", pageInfo);
        map.put("list",list );
        return "/page/recruit/interview/interview-list.html";
    }

    @RequestMapping("Wb")
    public String Wb(){return "/page/recruit/interview/interview-register.html";}

    //跳转到面结果登记
    @RequestMapping("Wb1")
    public String Wb1(int id,Map map){
        //通过id查询所有信息
        EngageResume e=jlgl.jlxxid(id);
        //查询职位
        Map zw=jlgl.zwmcid(id);
        //根据id查面试表和简历
        Map l=msgl.qc(id);
        map.put("l", l);
        map.put("e",e );
        map.put("m",zw );
        return "/page/recruit/interview/interview-register.html";
    }

    @RequestMapping("Wb4")
    public String Wb4(EngageResume ers,EngageInterview eit,Map map){
        //根据简历id修改面试表中的信息
        msgl.update(eit);
        //修改简历表的数量和未面试、待面试的状态
        msgl.updatesl(ers);
        return "redirect:a6";
    }

    //面试筛选
    @RequestMapping("a7")
    public String a7(Map map,
                     @RequestParam(defaultValue = "1",required = false) Integer startPage,
                     @RequestParam(defaultValue = "3",required = false) Integer PageSize){

        PageHelper.startPage(startPage, PageSize ); //使用分页插件
        //查询所有面试结果列表
       List<Map> l=msgl.cxjglb();
        PageInfo pageInfo=new PageInfo(l, 3); //保存分页信息
       map.put("l",l );
        map.put("pageInfo", pageInfo); //绑定分页信
        return "/page/recruit/interview/sift-list.html";
    }

    //面试筛选
    @RequestMapping("Wb2")
    public String Wb2(int id,Map map){
        //通过id查询所有信息
        EngageResume e=jlgl.jlxxid(id);
        //查询职位
        Map zw=jlgl.zwmcid(id);
        //根据id查面试表和简历
        Map l=msgl.qc(id);
        map.put("l", l);
        map.put("e",e );
        map.put("m",zw );
        return "/page/recruit/interview/interview-sift.html";
    }

    //添加
    @RequestMapping("Wb2tj")
    public String Wb2tj(EngageInterview eit,String result){
        EngageResume e=new EngageResume();
       if(result.equals("建议面试")){
            e.setInterview_status(1);
            //已筛选
            eit.setCheck_status(1);
            e.setRes_id(eit.getId());
            msgl.xgjl(e);
            msgl.xgmsb(eit);
        }
        if(result.equals("建议笔试")){
            System.out.println("笔试");
            e.setInterview_status(3);
            //已筛选
            eit.setCheck_status(1);
            e.setRes_id(eit.getId());
            msgl.xgjl(e);
            msgl.xgmsb(eit);
        }
        if(result.equals("建议录用")){
            e.setInterview_status(4);
            //已筛选
            eit.setCheck_status(1);
            e.setRes_id(eit.getId());
            msgl.xgjl(e);
            msgl.xgmsb(eit);
        }
        if(result.equals("删除简历")){
            //根据简历id删除简历和面试信息
            msgl.scjl(eit.getId());
            msgl.scmsxx(eit.getId());
        }
        return  "redirect:a7";
    }

}
